<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用 K-BSES 养老机构资质评估系统</title>
    <script src="lib/js/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="lib/css/bootstrap.min.css">
    <link rel="stylesheet" href="lib/css/css.css">
</head>
<body>
<div class="loginPage default">
    <div class="loginBox clearfix">
        <div class="center-block clearfix formBox">
            <div class="loginForm">
                <div>
                  <div style="font-size: 22px; margin-bottom:20px;">欢迎使用</div>
                  <div style="font-size: 18px; margin-bottom:30px;">K-BSES 养老机构资质评估系统</div>
                </div>
                <form>
                    <div class="input-group">
                        <label class="input-group-addon">用户名</label>
                        <input type="text" class="form-control" name="username" placeholder="用户名" />
                    </div>
                    <div class="input-group">
                        <label class="input-group-addon">密 码</label>
                        <input type="password" class="form-control" name="password" placeholder="密 码" />
                    </div>
                    <div>
                        <button class="btn btn-primary btn-right" style="width: 100%; padding: 6px 0px; clocr: #555;" type="submit">登 陆</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" charset="UTF-8">
    function login () {
        if($("input[name='username']").val() === '' ||  $("input[name='password']").val() === ''){
            alert('请输入用户名和密码！');
            return false
        }
        $.ajax({
            url: "login",
            type: "POST",
            data: $("form").serialize(),  // serializeArray()
            dataType: 'json',
            success: function (data, textStatus) {
                localStorage.setItem("userData", JSON.stringify(data.data));
                window.location.href = "/";
            },
            error: function(httpRequest, textStatus, errorThrown) {
                // console.log(httpRequest, textStatus, errorThrown);
                alert(httpRequest.responseJSON.message);
            }
        });
        return false;
    }
    $( "form" ).on( "submit", function( event ) {
        event.preventDefault();
        login ();
    });
</script>
</html>